 <?php
	/**
 * Enter description here ...
 * @author josue
 *
 * tags
 */
 
 
 class Usuario_model extends CI_Model{
 	
 	var $username = "";
 	var $password = "";
 	var $dbid = "";
 	
 	public function __construct(){
 		parent::__construct();
 		//cargando la base de datos default de la aplicación (login database)
 		
 	}
 	

 	
 	public function get_all_usuarios(){
 		$this->load->database('maindb');
 		$this->db->close();
 		$query = $this->db->get(LOGIN_TABLE);
 		
 		return $query->result();
 	}
 	
 	
 	
 	
 	public function valida_usuario($username,$password){
 		$query = $this->get_all_usuarios();
 		
 		foreach($query as $row){
 			if($row->username == $username && (crypt($password,$row->password) == $row->password) ){
 				return true;
 			}
 		}
 		
 		return false;
 		
 	}
 	public function get_usuario_by_username($username){
 	
 		$this->db->from(LOGIN_TABLE);
 		$this->db->where('username',$username);
 		$query = $this->db->get();
 		$this->db->close();
 		return $query->result();
 		
 	}
 	
 	public function get_database($dbid){
 		
 		$this->db->from(TKM_DB_TABLE);
 		$this->db->where('id',$dbid);
 		$query = $this->db->get();
 		$this->db->close();
 		return $query->result();
 	}
 	
 }
	
?>